package com.happyclub.paul.dao;

import com.happyclub.pojo.TbAlbumPhotoMap;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @Auther: 魏泉琦
 * @Date: 2019/4/7 11:50
 * @Description: 相册相片中间表
 */
public interface AlbumPhotoMapRepostitory extends JpaRepository<TbAlbumPhotoMap,String> {

    /**
     *@Description: 通过相册编号查询拥有的相片
     *@Author: 魏泉琦
     *@date: 2019/4/7
     */
    @Query("SELECT apm from TbAlbumPhotoMap apm where apm.photoAlbumId=?1")
    List<TbAlbumPhotoMap> queryAlbumPhotosByaAlbumId(String albumId);


    /**
     *@Description: 通过相册编号删除中间表数据
     *@Author: 魏泉琦
     *@date: 2019/4/9
     */
    @Modifying
    @Query(value = "DELETE from TB_ALBUM_PHOTO_MAP where PHOTO_ALBUM_ID=?1",nativeQuery = true)
    Integer deletePhotoAlbumMapByAlbumId(String albumId);

    /**
     *@Description: 相片审核成功，将相册相片信息插入中间表
     *@Author: 魏泉琦
     *@date: 2019/4/11
     */
    @Modifying
    @Query(value = "INSERT INTO TB_ALBUM_PHOTO_MAP(PHOTO_ALBUM_ID,PHOTO_ID,CREATE_TIME) VALUES(?1,?2,SYSDATE)",nativeQuery = true)
    Integer createPhotoAlbumMapByAlbumIdAndPhotoId(String albumId,String photoId);


    /**
     *@Description: 通过相片编号查询对应相片信息
     *@Author: 魏泉琦
     *@date: 2019/4/12
     */
    TbAlbumPhotoMap queryTbAlbumPhotoMapByPhotoId(String photoId);
    
    /**
     *@Description: 通过相片编号删除相片
     *@Author: 魏泉琦
     *@date: 2019/4/12
     */
    Integer deleteTbAlbumPhotoMapByPhotoId(String photoId);
}
